<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"
	import="javax.ejb.*,javax.naming.*,java.text.*,java.util.*,com.tiger.cmpeb.sample4.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>フライトの表示</title>
</head>
<body>
<%
	//request.setCharacterEncoding("JISAutoDetect");

	InitialContext ctx = new InitialContext();

	FlightHome01 flightHome = (FlightHome01) ctx.lookup("comp/env/ejb/FlightBean01");
	ReservationHome01 reservationHome = (ReservationHome01) ctx.lookup("comp/env/ejb/ReservationBean01");

	javax.transaction.UserTransaction ut = (javax.transaction.UserTransaction) ctx.lookup("UserTransaction");
	//javax.transaction.UserTransaction ut = (javax.transaction.UserTransaction)ctx.lookup("java:comp/UserTransaction");

	ut.begin();

	Integer flightID = new Integer(request.getParameter("flightID"));
	Flight01 flight = flightHome.findByPrimaryKey(flightID);
	Collection reservations = flight.getReservation();
	Iterator it = reservations.iterator();

	SimpleDateFormat fomatter = new SimpleDateFormat("yy/MM/dd hh:mm");
%>

<table>
	<tr>
		<td>フライトID</td>
		<td><%=flight.getFlightID()%></td>
	</tr>
	<tr>
		<td>フライト名</td>
		<td><%=flight.getFlightName()%></td>
	</tr>
	<tr>
		<td>出発日時</td>
		<td><%=fomatter.format(flight.getDepartureDate())%></td>
	</tr>
	<tr>
		<td>出発地</td>
		<td><%=flight.getOrigin()%></td>
	</tr>
	<tr>
		<td>到着地</td>
		<td><%=flight.getDestination()%></td>
	</tr>
</table>

<%
	while (it.hasNext()) {
		Reservation01 reservation = (Reservation01) it.next();
%>
<hr />
<p>予約状況</p>
<table border="1">
	<tr>
		<td>予約ID</td>
		<td><%=reservation.getReservationID()%></td>
	</tr>
	<tr>
		<td>予約名</td>
		<td><%=reservation.getReservationName()%></td>
	</tr>
</table>

<%
	}
	ut.commit();
%>
</body>
</html>